import asyncio
from fastapi import FastAPI
from fastapi import Request
import uvicorn
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles

app = FastAPI()
app.mount("/static", StaticFiles(directory="static"))
templates = Jinja2Templates(directory="templates")


@app.get("/index")
async def index():
    return {"data": "index", "status": True}


@app.get("/home")
def home(request: Request):
    context = {
        'request': request,
        'name': 'wupeiqi',
        "age": 19,
        "hobby": ["篮球", "足球"],
        "info": {
            "city": "北京",
            "address": "昌平沙河"
        }
    }
    return templates.TemplateResponse('home.html', context)


if __name__ == '__main__':
    uvicorn.run("coding:app", host="127.0.0.1", port=9002)
